﻿Imports System.ComponentModel
Imports System.Runtime.InteropServices

<Designer(GetType(System.Windows.Forms.Design.ScrollableControlDesigner))> _
Public Class cTabPage
    Inherits TabPage


    <DllImport("Comctl32.dll", CallingConvention:=CallingConvention.Cdecl)> _
    Private Overloads Shared Function DllGetVersion(ByRef pdvi As DLLVERSIONINFO) As Integer
    End Function

    <DllImport("uxtheme.dll", CallingConvention:=CallingConvention.Cdecl)> _
    Private Overloads Shared Function IsAppThemed() As Boolean
    End Function

    <DllImport("uxtheme.dll", CallingConvention:=CallingConvention.Cdecl, CharSet:=CharSet.Unicode)> _
    Private Overloads Shared Function OpenThemeData(ByVal hwnd As IntPtr, ByVal pszClassList As String) As IntPtr
    End Function

    <DllImport("uxtheme.dll", CallingConvention:=CallingConvention.Cdecl)> _
    Private Overloads Shared Function GetThemePartSize(ByVal hTheme As IntPtr, ByVal hdc As IntPtr, ByVal iPartId As Integer, ByVal iStateId As Integer, ByRef prc As Rectangle, ByVal eSize As THEMESIZE, ByRef psz As Size) As Integer
    End Function

    <DllImport("uxtheme.dll", CallingConvention:=CallingConvention.Cdecl)> _
    Private Overloads Shared Function DrawThemeBackground(ByVal hTheme As IntPtr, ByVal hdc As IntPtr, ByVal iPartId As Integer, ByVal iStateId As Integer, ByRef pRect As Rectangle, ByVal pClipRect As IntPtr) As Integer
    End Function

    <DllImport("uxtheme.dll", CallingConvention:=CallingConvention.Cdecl)> _
    Private Overloads Shared Function CloseThemeData(ByVal htheme As IntPtr) As Integer
    End Function

    Private Structure DLLVERSIONINFO
        Friend cbSize As Integer
        Friend dwMajorVersion As Integer
        Friend dwMinorVersion As Integer
        Friend dwBuildNumber As Integer
        Friend dwPlatformID As Integer
        Public Sub New(ByVal ctrl As Control)
            cbSize = Marshal.SizeOf(GetType(DLLVERSIONINFO))
        End Sub
    End Structure

    Private Enum THEMESIZE As Integer
        TS_MIN
        TS_TRUE
        TS_DRAW
    End Enum

    Private Const TABP_BODY As Integer = 10
    Private Const WM_THEMECHANGED As Integer = &H31A

    Public Event TabHeaderMenuDroppedDown(ByVal sender As Object, ByVal e As EventArgs)


    Private bStyled As Boolean = True


    Public Sub New()
        MyBase.New()

        'This call is required by the Windows Form Designer.
        InitializeComponent()

        'Add any initialization after the InitializeComponent() call
        Me.BackColor = Color.White
    End Sub

    Public Sub New(ByVal Text As String)
        MyBase.New()
        MyBase.Text = Text

        InitializeComponent()
    End Sub

    Public Property TabHeaderContextMenuStrip() As ContextMenuStrip
        Get
            Return cMenu
        End Get
        Set(ByVal value As ContextMenuStrip)
            cMenu = value
        End Set
    End Property

    Private Sub cMenu_Opening(ByVal sender As System.Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles cMenu.Opening
        RaiseEvent TabHeaderMenuDroppedDown(sender, e)
    End Sub
End Class